<!DOCTYPE html>
<html lang="en">
<head>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }

            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
        <script type="text/javascript"
                src="https://webapi.amap.com/maps?v=1.4.15&key=38ec219a062bbf92f1f3ccd9a574752b">
        </script>
        <script src="https://a.amap.com/jsapi_demos/static/demos/requirejs/require.js"
                data-main="https://a.amap.com/jsapi_demos/static/demos/requirejs/require-init"></script>
        <style>
            #container {
                width: 700px;
                height: 600px;
            }
        </style>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    </head>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="分布图" name="first">
                    <div id="container"></div>
                </el-tab-pane>
                <el-tab-pane label="详细信息" name="second">
                    <div class="filter-container">
                        <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPageByqueryString()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>

                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row
                              ref="multipleTable"
                              @selection-change="changeFun">

                        <el-table-column type="index" align="center" label="序号"></el-table-column>


                        <el-table-column prop="orderDate" label="公司地址" align="center"></el-table-column>
                        <el-table-column prop="member.fileNumber" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="member.name" label="所在维度" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="cancelReservation(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
            </el-tabs>
        </div>
    </div>

</div>
</body>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            order: {},
            member: {},
            setmeal: {},
            multipleTable:[],
            orderIds:[],
            loading: true,

            autoUpload:true,//自动上传
            imageUrl:null,//模型数据，用于上传图片完成后图片预览
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//添加表单窗口中检查组列表数据
            setmealIds:[],//添加表单窗口中检查组复选框对应id
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false//控制编辑窗口显示/隐藏
        },
        created() {
            var map = new AMap.Map('container');
            var url = 'https://webapi.amap.com/maps?v=1.4.15&key=L5vjiT9u0XLsvx2R5EzG53DTRG5SAWQA&callback=onLoad';
            var jsapi = doc.createElement('script');
            jsapi.charset = 'utf-8';
            jsapi.src = url;
            document.head.appendChild(jsapi);
        },
        methods: {
            //条件查询
            findPageByqueryString(){
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //分页查询
            findPage() {
                //分页参数
                var param = {
                    currentPage:this.pagination.currentPage,//页码
                    pageSize:this.pagination.pageSize,//每页显示的记录数
                    queryString:this.pagination.queryString//查询条件
                };
                //请求后台
                axios.post("/order/findPage.do",param).then((response)=> {
                    //为模型数据赋值，基于VUE的双向绑定展示到页面
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },

            //确认预约
            ConfirmAppointment(row){
                this.$confirm("确定要预约吗?","提示",{
                    confirmButtonText: '确定预约',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(()=>{
                    axios.post("/order/ConfirmAppointment.do?id=" + row.id).then((resp)=>{
                        if (resp.data.flag) {
                            this.$message.success(resp.data.message)
                        } else {
                            this.$message.error(resp.data.message)
                        }
                    }).finally(()=>{
                        this.findPage();
                    })
                }).catch(()=>{
                    this.$message.info("已取消预约操作")
                })
            },

            //取消预约
            cancelReservation(row){
                this.$confirm("确定要取消预约吗?","提示",{
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(()=>{
                    axios.post("/order/cancelReservation.do?id=" + row.id).then((resp)=>{
                        if (resp.data.flag) {
                            this.$message.success(resp.data.message)
                        } else {
                            this.$message.error(resp.data.message)
                        }
                    }).finally(()=>{
                        this.findPage();
                    })
                }).catch(()=>{
                    this.$message.info("已取消该操作")
                })
            },


            // 重置表单
            resetForm() {
                this.formData = {};
                this.activeName = 'first';
                this.imageUrl = null;
                this.setmealIds = [];
            },
            // 弹出添加窗口
            handleCreate() {
                axios.post("/setmeal/findAll.do").then((resp)=>{
                    if (resp.data.flag){
                        this.tableData = resp.data.data;
                        this.resetForm();
                        this.dialogFormVisible = true;
                    }else{
                        this.$message.error(resp.data.message);
                    }
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //切换每页显示条数
            handleSizeChange(pageSize){
                this.pagination.pageSize = pageSize;
                this.findPage();
            },
            //添加
            handleAdd(){

                this.member = {
                    "name":this.formData.name,
                    "idCard":this.formData.idCard,
                    "birthday":this.formData.birthday,
                    "phoneNumber":this.formData.phoneNumber,
                    "sex":this.formData.sex,
                    "age":this.formData.age,
                    "marry":this.formData.marry,
                };
                this.order = {
                    "orderDate":this.formData.orderDate,
                };

                axios.post("/order/add.do?setmealIds=" + this.setmealIds + "&order_Date=" + this.formData.orderDate,this.member).then((resp)=>{
                    if (resp.data.flag){
                        this.$message.success(resp.data.message);
                    }else{
                        this.$message.error(resp.data.message);
                    }
                }).finally(()=>{
                    this.dialogFormVisible = false;
                    this.findPage();
                })
            },

            changeFun(){
                this.multipleTable = this.$refs.multipleTable.selection;
            },

            //批量取消预约
            toggleSelection(){
                for (var i = 0; i < this.multipleTable.length; i++) {
                    this.orderIds[i] = this.multipleTable[i].id;
                }

                this.$confirm("确定要批量取消预约吗?","提示",{
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(()=>{
                    axios.post("/order/batchCancelReservation.do?orderIds="+this.orderIds).then((resp)=>{
                        if (resp.data.flag) {
                            this.$message.success(resp.data.message)
                        } else {
                            this.$message.error(resp.data.message)
                        }
                    }).finally(()=>{
                        this.findPage();
                    })
                }).catch(()=>{
                    this.$message.info("已取消该操作")
                })
            }
        }
    });

</script>
</html>